<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="lib/layui/css/layui.css">
    <script src="lib/layui/layui.js"></script>
    <script src="lib/jquery-1.12.4.min.js"></script>
    <link rel="stylesheet" href="lib/mmGrid/mmGrid.css">
    <link rel="stylesheet" href="lib/mmGrid/mmPaginator.css">
    <link rel="stylesheet" href="lib/mmGrid/mmGrid-bootstrap.css">
    <script type="text/javascript" src="lib/mmGrid/mmGrid.js"></script>
    <script type="text/javascript" src="lib/mmGrid/mmPaginator.js"></script>
    <script>
        document.write('<link rel="stylesheet" href="lib/common.css?t=' + new Date().getTime() + '">')
        document.write('<script src="lib/lib.js?t=' + new Date().getTime() + '"><\/script\>')
        document.write('<script src="lib/api.js?t=' + new Date().getTime() + '"><\/script\>')
    </script>

    <style>
        .layui-tab-title{
            float: left;
            border-bottom: none;
        }
        .layui-tab-title li{
            display: block;
        }
        .layui-tab-content{
            width: 85%;
            margin-left:15%;
        }
        .layui-tab-title .layui-this{background: #e2e2e2;}/* 增加背景 */
        .layui-tab-title .layui-this:after{border: none;}/* 重置 -this无边框 */

        .form-horizontal .control-group{
            margin-bottom: 0;
        }
       .form-horizontal .control-label{
            width: 100px;
       }
       .form-horizontal .controls{
            margin-left: 110px;
       }
       .form-horizontal .controls span{
            line-height: 30px;
       }
    </style>
</head>
<body>
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">公司简介</li>
            <li>现货资源</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="form-horizontal" id="form">
                    <table style="width: 100%;">
                        <tr>
                            <td>
                                <div class="control-group">
                                    <label class="control-label" for="name">公司名称</label>
                                    <div class="controls">
                                        <span id="name"></span>
                                    </div>
                                </div>
                            </td>
                            <td>
                                <div class="control-group">
                                    <label class="control-label" for="name">简称</label>
                                    <div class="controls">
                                        <span id="abbName"></span>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="control-group">
                                    <label class="control-label" for="linkman">联系人</label>
                                    <div class="controls">
                                        <span id="linkman"></span>
                                    </div>
                                </div>
                            </td>
                            <td>
                                <div class="control-group">
                                    <label class="control-label" for="phone">电话</label>
                                    <div class="controls">
                                        <span id="phone"></span>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="control-group">
                                    <label class="control-label" for="fax">传真</label>
                                    <div class="controls">
                                        <span id="fax"></span>
                                    </div>
                                </div>
                            </td>
                            <td>
                                <div class="control-group">
                                    <label class="control-label" for="province">省份</label>
                                    <div class="controls">
                                        <span id="province"></span>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="control-group">
                                    <label class="control-label" for="postal_code">邮政编码</label>
                                    <div class="controls">
                                        <span id="postal_code"></span>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div class="control-group">
                                    <label class="control-label" for="bank">开户银行</label>
                                    <div class="controls">
                                        <span id="bank"></span>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div class="control-group">
                                    <label class="control-label" for="mailing_address">通讯地址</label>
                                    <div class="controls">
                                        <span id="mailing_address"></span>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div class="control-group">
                                    <label class="control-label" for="bizManager1">业务经理1</label>
                                    <div class="controls">
                                        <span id="bizManager1"></span>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div class="control-group">
                                    <label class="control-label" for="bizManager2">业务经理2</label>
                                    <div class="controls">
                                        <span id="bizManager2"></span>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div class="control-group">
                                    <label class="control-label" for="bizManager3">业务经理3</label>
                                    <div class="controls">
                                        <span id="bizManager3"></span>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div class="control-group">
                                    <label class="control-label" for="remark">备注</label>
                                    <div class="controls">
                                        <span id="remark"></span>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
            <div class="layui-tab-item">
                <table id="mmg" class="mmg" style="width: 100%;"></table>
                <div id="pg" style="text-align: right;"></div>
            </div>
        </div>
    </div>

    <script>
        var id = getUrlParams('id')
        var element,
            laypage,
            layer,
            mmg,
            current=1,
            size=20;

        var page = {
            companyDetail: function () {
                var post = {
                    id: id
                }
                api.companyDetail(post, function (res){
                    if (res.code==200){
                        var data =res.data
                        $("#name").html(data.name)
                        $("#abbName").html(data.abbName)
                        $("#bizManager1").html(data.bizManager1)
                        $("#bizManager2").html(data.bizManager2)
                        $("#bizManager3").html(data.bizManager3)
                        $("#fax").html(data.fax)
                        $("#linkman").html(data.linkman)
                        $("#mailing_address").html(data.mailing_address)
                        $("#phone").html(data.phone)
                        $("#bank").html(data.bank)
                        $("#postal_code").html(data.postal_code)
                        $("#province").html(data.province)
                    }
                })
            },
            stockList: function (table) {
                var post = {
                    current: current,
                    size: size,
                    companyId: id
                }
                api.stockList(post, function (res) {
                    if (res.code == 200) {
                        if (table) {
                            mmg.load(res.data.records)
                        } else {
                            page.createTable(res.data)
                        }
                    }
                })
            },
            createTable: function (data) {
                mmg = $('.mmg').mmGrid({
                    height: $(window).height() - 150,
                    showBackboard: false,
                    cols: [
                        {
                            title: '品种',
                            name: 'varieties',
                            width: 100,
                            align: 'left'
                        },
                        {
                            title: '产地',
                            name: 'place',
                            align: 'center'
                        },
                        {
                            title: '规格',
                            name: 'spec',
                            width: 50,
                            align: 'center'
                        },
                        {
                            title: '材质',
                            name: 'textureMaterial',
                            width: 60,
                            align: 'center'
                        },
                        {
                            title: '库存数量',
                            name: 'quantity',
                            width: 60,
                            align: 'center'
                        },
                        {
                            title: '发布时间',
                            name: 'createTime',
                            align: 'center'
                        }
                    ],
                    items: data.records,
                    fullWidthRows: true,
                    plugins: [
                        laypage.render({
                            elem: 'pg',
                            count: data.total,
                            limit: size,
                            curr: current,
                            layout: ['prev', 'page', 'limit', 'next'],
                            jump: function (obj, first) {
                                size = obj.limit
                                if (!first) {
                                    current = obj.curr
                                    page.stockList(true)
                                }
                            }
                        })
                    ]
                })
            },
            showEnquiry: function(id){
                if(Cookie.get('bladeAuth')){
                    if(Cookie.get('level')==0){
                        showMember()
                    } else{
                        layer.open({
                            type: 2,
                            title: '询价',
                            area: ['360px', '300px'],
                            content: 'enquiry.html?id='+id
                        })
                    }
                } else {
                    showLogin()
                }
            }
        }
        layui.use(['element','laypage', 'layer', 'table'], function(){
            element = layui.element
            laypage = layui.laypage
            layer = layui.layer
            laytable = layui.table
            page.companyDetail()
            page.stockList()
            $(document).on('keydown', function(ev){
                if(ev.keyCode==27){
                    var index = parent.layer.getFrameIndex(window.name)
                    parent.layer.close(index)
                }
            })
        })
    </script>
</body>
</html>
